
const Version = new Date().getTime();
const path = require('path');
function resolve(dir) {
  return path.join(__dirname, dir)
}
module.exports = {

  //部署应用包时的基本 URL
  publicPath: process.env.NODE_ENV === "production" ? "./" : "./",
  //当运行 vue-cli-service build 时生成的生产环境构建文件的目录
  outputDir: 'lottery_vue',
  //放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录
  assetsDir: './assets',

  // 生产环境是否生成 sourceMap 文件 sourceMap的详解请看末尾  
  productionSourceMap: false,
  devServer: {
    overlay: {
      warnings: false,
      errors: false
    },
    hot: true, //热加载
    host: 'localhost',//'192.168.10.104', //ip地址
    https: false, //false关闭https，true为开启
    open: true, //自动打开浏览器
    proxy: {	 //配置多个跨域
      '/api': { //本地 
        //target: 'http://172.168.10.150:81/ysol_wx',
        target: 'https://yishanol.cn/ysol_dou_trans',
        //target: 'http://yishanonline.cn/ysol_dou_trans',
        ws: true,
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      },
      '/lottery': { //本地 
        //target: 'http://172.168.10.150:81/ysol_eshop',
        // target: 'http://192.168.10.115/ysol_eshop',
        target: 'https://yishanol.cn/ysol_eshop',
        ws: true,
        changeOrigin: true,
        pathRewrite: {
          '^/lottery': ''
        }
      },
    }
  },
  lintOnSave: false,
  configureWebpack: config => {
    if (process.env.NODE_ENV === 'production') {
      // 为生产环境修改配置...
      config.mode = 'production'
      config.devtool = "source-map";
    } else {
      // 为开发环境修改配置...
      config.mode = 'development'
    }
    /** 删除懒加载模块的 prefetch preload，降低带宽压力(使用在移动端) */
    config.plugins.delete("prefetch").delete("preload")
    config.optimization.minimize(true)



    // 公共代码抽离
    config.optimization = {
      splitChunks: {
        cacheGroups: {
          vendor: {
            chunks: 'all',
            test: /node_modules/,
            name: 'vendor',
            minChunks: 1,
            maxInitialRequests: 5,
            minSize: 0,
            priority: 100
          },
          common: {
            chunks: 'all',
            test: /[\\/]src[\\/]js[\\/]/,
            name: 'common',
            minChunks: 2,
            maxInitialRequests: 5,
            minSize: 0,
            priority: 60
          },
          styles: {
            name: 'styles',
            test: /\.(sa|sc|c)ss$/,
            chunks: 'all',
            enforce: true
          },
          runtimeChunk: {
            name: 'manifest'
          }
        }
      }
    }
  },
  configureWebpack: {
    resolve: {
      alias: {
        'vue$': 'vue/dist/vue.esm.js',
        '@': resolve('src'),
        '@c': path.resolve(__dirname, './src/components'),
        'assets': path.resolve(__dirname, './src/assets')
      }
    },
  },
  css: {
    loaderOptions: {
      css: {},
      postcss: {
        plugins: [
          require('postcss-px2rem-exclude')({
            remUnit:75,//37.5
            exclude:"/node_modules/vant" // 忽略node_modules目录下的文件
          })
        ]
      }
    }
  },
}